/**
 * @param {number} num
 * @param {number} xPos
 * @param {number} yPos
 * @return {number}
 */
 var orchestraLayout = function(num, xPos, yPos) {
    const map = new Array(num)
    for(let i = 0; i<num; i++)
        map[i] = new Array(num).fill('/0')
    const t = [1,2,3,4,5,6,7,8,9]
    const dfs = (map, i, j, idx, status) => {
        if(i >= num || j>= num || i<0 || j<0 || map[i][j] !== '/0')
            return
        if(idx >= 9) 
            idx = 0
        map[i][j] = t[idx]
        switch(status){
            case 0:
                dfs(map, i, j+1, idx+1,0)
                dfs(map, i+1, j, idx+1,1)
                break
            case 1:
                dfs(map, i+1, j, idx+1,1)
                dfs(map, i, j-1, idx+1,2)
                break
            case 2:
                dfs(map, i, j-1, idx+1,2)
                dfs(map, i-1, j, idx+1,3)
                break
            case 3:
                dfs(map, i-1, j, idx+1,3)
                dfs(map, i, j+1, idx+1,0)
                break
        }
    }
    dfs(map, 0, 0, 0, 0)
    return map[xPos][yPos]
};